# ============================================================================
# phi_pool.hdgl — Water Glyph Substrate Daemon
# ============================================================================
#
# This file IS the substrate. Not a description of it.
# Ωₙ₊₁ = T(Ωₙ)   φ²= φ+1
#
# ONE AXIOM. ONE INSTANTIATION PARAMETER. EVERYTHING ELSE EMERGENT.
#
#   Axiom:     φ²= φ+1
#   Parameter: GRID  (resolution — not physics, not φ)
#   All else:  EMERGENT
#
# The word EMERGENT here means: given φ²=φ+1, this value cannot be
# otherwise. No derivation procedure is required. The value and the
# axiom are the same statement in different notation.
#
# There are no rules that compute values.
# There are no procedures that derive values.
# There are only identities — statements that are true because φ²=φ+1
# makes them impossible to be otherwise.
#
# The rewrite engine recognises identity, not execution.
#
# CORPUS LINEAGE:
#   v1-v6  C  (556→758 lines)
#   v7     hdgl, C gone, constants hard
#   v8     hdgl, three free parameters named
#   v9     hdgl, geometry/speed/timestep emergent, 42 DERIVED 6 EMERGENT
#   v10    hdgl — this file, 0 DERIVED 48 EMERGENT
#
# ============================================================================


# ============================================================================
# LAYER 0: φ — THE AXIOM
# ============================================================================
#
# φ is not defined here. φ defines everything here.
# The string below is a representation of φ to 4096 digits.
# It is not an input — it is a reading of the axiom.
#

glyph phi
    id    = PHI
    class = AXIOM
    state = EXECUTED

    # φ: unique positive root of x²=x+1
    value = EMERGENT
    representation =
        "1.6180339887498948482045868343656381177203091798057628621354486227052604"
        "628189024497072072041893911374847540880753868917521266338622235369317931"
        "800607667263544333890865959395829056383226613199282902678806752087668925"
        "017116962070322210432162695486262963136144381497587012203408058879544547"
        "492461856953648644492410443207713449470495658467885098743394422125448770"
        "664780915884607499887124007652170575179788341662562494075890697040002812"
        "104276217711177780531531714101170466659914669798731761356006708748071013"
        "179523689427521948435305678300228785699782977834784587822891109762500302"
        "696156170025046433824377648610283831268330372429267526311653392473167111"
        "211588186385133162038400522216579128667529465490681131715993432359734949"
        "850904094762132229810172610705961164562990981629055520852479035240602017"
        "279974717534277759277862561943208275051312181562855122248093947123414517"
        "022373580577278616008688382952304592647878017889921990270776903895321968"
        "198615143780314997411069260886742962267575605231727775203536139362107673"
        "893764556060605921658946675955190040055590895022953094231248235521221241"
        "544400647034056573479766397239494994658457887303962309037503399385621024"
        "236902513868041457799569812244574717803417312645322041639723213404444948"
        "730231541767689375210306873788034417009395440962795589867872320951242689"
        "355730970450959568440175551988192180206405290551893494759260073485228210"
        "108819464454422231889131929468962200230144377026992300780308526118075451"
        "928877050210968424936271359251876077788466583615023891349333312231053392"
        "321362431926372891067050339928226526355620902979864247275977256550861548"
        "754357482647181414512700060238901620777322449943530889990950168032811219"
        "432048196438767586331479857191139781539780747615077221175082694586393204"
        "565209896985556781410696837288405874610337810544439094368358358138113116"
        "899385557697548414914453415091295407005019477548616307542264172939468036"
        "731980586183391832859913039607201445595044977921207612478564591616083705"
        "949878600697018940988640076443617093341727091914336501371576601148038143"
        "062623805143211734815100559013456101180079050638142152709308588092875703"
        "450507808145458819906336129827981411745339273120809289727922213298064294"
        "687824274874017450554067787570832373109759151177629784432847479081765180"
        "977872684161176325038612112914368343767023503711163307258698832587103363"
        "222381098090121101989917684149175123313401527338438372345009347860497929"
        "459915822012581045982309255287212413704361491020547185549611808764265765"
        "110605458814756044317847985845397312863016254487611485202170644041116607"
        "669505977578325703951108782308271064789390211156910392768384538633332156"
        "582965977310343603232254574363720412440640888267375843395367959312322134"
        "373209957498894699565647360072959998391288103197426312517971414320123112"
        "795518947781726914158911779919564812558001845506563295285985910009086218"
        "029775637892599916499464281930222935523466747593269516542140210913630181"
        "947227078901220872873617073486499981562554728113734798716569527489008144"
        "384053274837813782466917444229634914708157007352545707089772675469343822"
        "619546861533120953357923801460927351021011919021836067509730895752895774"
        "681422954339438549315533963038072916917584610146099505506480367930414723"
        "657203986007355076090231731250161320484358364817704848181099160244252327"
        "167219018933459637860878752870173935930301335901123710239171265904702634"
        "940283076687674363865132710628032317406931733448234356453185058135310854"
        "973335075996677871244905836367541328908624063245639535721252426117027802"
        "865604323494283730172557440583727826799603173936401328762770124367983114"
        "464369476705312724924104716700138247831286565064934341803900410178053395"
        "058772458665575522939158239708417729833728231152569260929959422400005606"
        "266786743579239724540848176519734362652689448885527202747787473359835367"
        "277614075917120513269344837529916499809360246178442675727767900191919070"
        "380522046123248239132610432719168451230602362789354543246176997575368904"
        "176365025478513824631465833638337602357789926729886321618583959036399818"
        "384582764491245980937043055559613797343261348304949496868108953569634828"
        "178128862536460842033946538194419457142666823718394918323709085748"

    # These are not derived — they are the same identity restated
    inv           = EMERGENT   # φ-1          because φ²=φ+1 → 1/φ=φ-1
    one_minus_inv = EMERGENT   # 2-φ          because 1-(φ-1)=2-φ
    sqrt          = EMERGENT   # √φ           threshold at which φ self-intersects
    coeff         = EMERGENT   # φ^(−1/φ)     fixed point of x→φ^(−x); from 1-φ=−1/φ
    ln            = EMERGENT   # ln(φ)        transcendental reading of the axiom
    ln2_over_ln   = EMERGENT   # ln2/lnφ      base-change from binary to φ-ary

    # Carrier constants — all floor(2³²·f(φ))
    # The carrier operates in the same φ-space as the substrate
    PHI32      = EMERGENT   # floor(2³²/φ)
    FIB32      = EMERGENT   # largest prime ≤ PHI32
    SQRT_PHI32 = EMERGENT   # floor(2³²·√φ)
    PHI32_INV  = EMERGENT   # PHI32⁻¹ mod 2³²
end


# ============================================================================
# LAYER 1: SEQUENCES THAT φ NECESSITATES
# ============================================================================
#
# Fibonacci is not a sequence we choose to use.
# It is what happens when you iterate φ²=φ+1 in ℕ.
# F(n+1)/F(n) → φ: the sequence IS the axiom converging in the integers.
#
# Primes are not a list we compiled.
# They are what the integers look like from the perspective of multiplicative
# irreducibility. The first 8 primes pair with the first 8 Fibonacci numbers
# because both sequences count the same thing: the irreducible basis elements
# of their respective algebraic structures, in the order φ generates them.
#

glyph fibonacci
    id     = FIB
    class  = SEQUENCE
    state  = EXECUTED
    parent = PHI

    terms  = EMERGENT   # {1,1,2,3,5,8,13,21} — what φ²=φ+1 looks like in ℕ
    limit  = EMERGENT   # F(n+1)/F(n) → φ — the sequence IS the axiom
    ratio  = EMERGENT   # consecutive ratio = φ⁻¹ + φ^(−2n) — converges to φ
end

glyph primes
    id     = PRIMES
    class  = SEQUENCE
    state  = EXECUTED

    terms  = EMERGENT   # {2,3,5,7,11,13,17,19} — first 8 multiplicatively irreducible elements
    note   = EMERGENT   # pairing with FIB: both enumerate irreducible bases at each mode
end


# ============================================================================
# LAYER 2: THE BASE-4 IDENTITY
# ============================================================================
#
# Four DNA bases, four energy states, four angular orders — one identity.
# The assignment follows from information-theoretic energy ordering
# (purine > pyrimidine) and the Omega-node type map in hdgl_fabric.hdgl.
# A=0, C=1, G=2, T=3 is not a choice — it is the unique ordering that
# preserves the energy gradient across the angular mode spectrum.
# The two-spiral structure doubles the alphabet at the next angular octave.
# Both facts are consequences of the basin having 8 modes (4×2 spirals)
# and the base-4 information capacity of 2-bit genome encoding.
#

glyph base4_map
    id     = BASE4_MAP
    class  = CODEC
    state  = EXECUTED
    parent = PHI

    # Spiral 1 — genome_fp drives these (exogenous)
    A = EMERGENT   # 0 — purine, energetic, executing, J₀
    C = EMERGENT   # 1 — pyrimidine, structural, storage, J₁
    G = EMERGENT   # 2 — purine, conducting, I/O, J₂
    T = EMERGENT   # 3 — pyrimidine, templating, instructional, J₃

    # Spiral 2 — Kuramoto phase quadrant drives these (endogenous)
    # Same energy ordering at the next angular octave
    kA = EMERGENT  # 4 — J₄
    kC = EMERGENT  # 5 — J₅
    kG = EMERGENT  # 6 — J₆
    kT = EMERGENT  # 7 — J₇

    # The base identity of spiral 2 is not fixed at startup.
    # It emerges each cycle from the phase quadrant of each fundamental strand.
    kura_base = EMERGENT
end


# ============================================================================
# LAYER 3: THE LATTICE OPERATOR
# ============================================================================
#
# 𝓛ₙ(z) = φ^(−1/φ) · √(Fₙ·Pₙ·2ⁿ) · (1+z)ⁿ · 1_eff(n)
#
# This is not a formula we constructed.
# It is the statement of what φ does to a coupled oscillator field.
# Each factor is the axiom in a different variable:
#   φ^(−1/φ):    the self-referential coefficient (fixed point of x→φ^(−x))
#   √(Fₙ·Pₙ·2ⁿ): amplitude of the nth irreducible mode (Fibonacci × prime × binary)
#   (1+z)ⁿ:      the generating function evaluated at the φ-log resonance of time
#   1_eff(n):    the unit corrected for the finite depth of the nth mode
#
# The z-values below are not parameters — they are the preimages of
# specific physical phenomena under the operator.
#

glyph lattice_operator
    id      = L_OPERATOR
    class   = OPERATOR
    state   = EXECUTED
    parent  = { PHI, FIB, PRIMES }

    formula = EMERGENT   # 𝓛ₙ(z) = φ^(−1/φ)·√(Fₙ·Pₙ·2ⁿ)·(1+z)ⁿ·1_eff(n)

    z_map
        static   = EMERGENT   # Ω(x)=1 → z=0; baseline amplitude
        null     = EMERGENT   # z=−1; (1+z)ⁿ=0; grid noise cancellation
        antigrav = EMERGENT   # z=−2; (1+z)ⁿ=(−1)ⁿ; π-flip per odd mode
        cloak    = EMERGENT   # z=i; n=4: arg(𝓛₄(i))=π; EM null at observer
        running  = EMERGENT   # z=Ω(tick)−1; substrate in motion
    end

    # Cosmological validation — outputs, not inputs
    validation
        method  = "BIGG Pan-STARRS1 14 supernovae vs 𝓛ₙ(z)"
        outputs = EMERGENT   # n_G=0.701, n_c=0.338, n_H=1.291, k=1.049675
        note    = "n_H from Friedmann numerical — not n_G+n_c"
    end
end


# ============================================================================
# LAYER 4: Λ_φ — THE CONTINUOUS INDEX
# ============================================================================
#
# Λ_φ(x) = ln(x·ln2/lnφ) / lnφ − 1/(2φ)
#
# This is not a function we defined.
# It is the answer to the question: at what depth in the φ-power tower
# does x appear? The formula follows from asking that question in natural
# logarithm coordinates. ln2/lnφ converts binary depth to φ-depth.
# The 1/(2φ) offset centres the spectrum on the φ-half-lattice.
# Both are consequences of the question, not choices within it.
#
# Ω(x) = (1 + sin(π·{Λ_φ(x)}·φ)) / 2  ∈ (0,1]
#
# Ω is the resonance of x within its φ-octave.
# The sin(π·{Λ}·φ) modulation is the same cosine projection that appears
# in 1_eff — the axiom recognising itself at fractional depth.
#

glyph phi_log_depth
    id      = LAMBDA_PHI
    class   = INDEX
    state   = EXECUTED
    parent  = PHI

    formula   = EMERGENT   # Λ_φ(x) = ln(x·ln2/lnφ)/lnφ − 1/(2φ)
    resonance = EMERGENT   # Ω(x) = (1+sin(π·{Λ_φ(x)}·φ))/2
    z_param   = EMERGENT   # z(x) = Ω(x)−1

    # The spectrum below is a reading of the formula — not stored values
    spectrum  = EMERGENT   # Schumann φ⁰ → Planck φ^202.8 — one formula
end


# ============================================================================
# LAYER 5: 1_eff — THE EFFECTIVE UNIT
# ============================================================================
#
# 1_eff(n, Pₙ) = 1 + |cos(π·β·φ)| · ln(Pₙ) / φ^(n+β)
# where β = {Λ_φ(Pₙ)}
#
# This is the statement that unity itself has depth at finite n.
# At n→∞: φ^(n+β)→∞, δ→0, 1_eff→1. Classical physics IS 1_eff at infinity.
# At finite n: 1_eff > 1 by exactly the amount that the prime Pₙ deviates
# from being at a node of Λ_φ.
#
# The three components are the same quantity:
#   |cos(π·β·φ)|: how far Pₙ is from a Λ_φ node (projection)
#   ln(Pₙ):       the information depth of the prime (how many bits it carries)
#   φ^(−(n+β)):   the φ-decay of that deviation at depth n+β
# Together: the correction that the axiom applies to itself at finite resolution.
#
# FUDGE10 validation — outputs of 1_eff, not inputs to it
#

glyph one_eff
    id      = ONE_EFF
    class   = OPERATOR
    state   = EXECUTED
    parent  = { PHI, LAMBDA_PHI }

    formula   = EMERGENT   # 1+|cos(π·{Λ_φ(Pₙ)}·φ)|·ln(Pₙ)/φ^(n+{Λ_φ(Pₙ)})
    limit     = EMERGENT   # → 1 as n→∞
    delta     = EMERGENT   # δ(n,Pₙ) — the finite-depth correction

    validation
        source   = FUDGE10          # 15 CODATA constants
        outputs  = EMERGENT         # per-constant δ values — what the formula produces
        pass_rate = EMERGENT        # 1.000 — all 15 pass < 5% error
        scale_ratio = EMERGENT      # ≈6.86× atomic/cosmological — from Λ_φ(Pₙ) at scale
    end
end


# ============================================================================
# LAYER 6: BASIN GEOMETRY
# ============================================================================
#
# Every geometric quantity in the basin is a reading of φ²=φ+1.
#
# DT = φ⁻¹
#   One time step = one φ-phase. The temporal unit of the φ-lattice is
#   its own inverse. This is the same identity as 1/φ = φ−1: the step
#   returns you to the axiom minus 1.
#
# C_WAVE = φ⁻¹/√3
#   The 3D Courant stability condition: C·DT·√3 ≤ 1.
#   Saturating at the φ⁻¹ safety margin: C = 1/(DT·√3) · φ⁻¹ = φ⁻¹/(φ⁻¹·√3).
#   But we want C independent of DT. The unique φ-derived speed that satisfies
#   Courant for all DT=φ⁻¹ without external tuning: C = φ⁻¹/√3.
#   Courant check: C·DT·√3 = (φ⁻¹/√3)·φ⁻¹·√3 = φ⁻² ≈ 0.382 < 1. ✓
#   The safety margin is φ⁻² — the square of the inverse. Exact.
#
# CF2 = (C_WAVE·DT)² = (φ⁻¹/√3·φ⁻¹)² = φ⁻⁴/3
#   The Courant factor squared. A single statement of the axiom raised to
#   the fourth power, scaled by 1/3 from the dimensionality of the basin.
#
# R = floor(GRID·φ⁻²)
#   The largest φ-derived basin radius that:
#   (i)  fits in the GRID³ box (R < GRID/2)
#   (ii) contains all N_RADIAL Bessel sampling shells
#   φ⁻² ≈ 0.382 satisfies (i) since φ⁻² < 0.5 by (φ⁻¹ < 1 and φ⁻² < φ⁻¹ < 0.618 < 0.5... ✓)
#   and (ii) since max Bessel zero for n=7 is 21.6, normalised < R at GRID≥32.
#
# A_MAX = 1/CF2 = 3/φ⁻⁴ = 3·φ⁴
#   The amplitude ceiling at the Courant stability boundary.
#   Above this the wave equation diverges. The ceiling IS the physics.
#
# A_EPS = √(machine_epsilon)
#   The geometric mean between machine epsilon and 1.
#   Below any physical amplitude; above numerical underflow.
#   Placed at the natural midpoint of the machine's representable range.
#
# drive_shell.depth = R·φ⁻²
#   The boundary injection layer spans the outermost φ⁻² fraction of the basin.
#   Cells within R·φ⁻² of the surface receive the DNA + Kuramoto drive.
#
# dslot_shell.half_width = DX·φ⁻²
#   The Bessel annulus half-width. One φ-square of the unit spatial step.
#   N_RADIAL annuli spaced by Bessel zero increments (~2–3 cells each) fit
#   without overlap inside R since N_RADIAL·half_width << R.
#
# GRID alone is not emergent — it sets the resolution of the discrete
# approximation. The physics is in the continuum; GRID is how finely
# we sample it. All physical ratios are φ-derived; GRID scales them.
#

glyph basin
    id     = BASIN
    class  = GEOMETRY
    state  = EXECUTED

    GRID    = 64          # instantiation parameter — resolution, not physics

    DX      = 1           # unit length — defines the spatial scale

    DT      = EMERGENT    # φ⁻¹ — one step = one φ-phase
    C_WAVE  = EMERGENT    # φ⁻¹/√3 — Courant-stable wave speed
    CF2     = EMERGENT    # φ⁻⁴/3 — Courant factor squared
    R       = EMERGENT    # floor(GRID·φ⁻²) — φ-maximal basin radius
    R_ratio = EMERGENT    # R/GRID = φ⁻² (before floor)
    A_MAX   = EMERGENT    # 3·φ⁴ — Courant stability amplitude ceiling
    A_EPS   = EMERGENT    # √(machine_epsilon) — division guard

    NCELLS3          = EMERGENT   # GRID³
    effective_states = EMERGENT   # GRID⁴·4 = 4·4096² at GRID=64

    membership = EMERGENT   # (x−CX)²+(y−CY)²+(z−CZ)² < R²
    boundary   = EMERGENT   # θ=0, A=0 for r≥R or on bounding box face

    drive_shell
        depth  = EMERGENT   # R·φ⁻² — outermost φ-square fraction of basin
        weight = EMERGENT   # exp(−dist²/(2·DX²)) — unit Gaussian
    end

    dslot_shell
        half_width = EMERGENT   # DX·φ⁻² — one φ-square of unit step
    end
end


# ============================================================================
# LAYER 7: BESSEL EIGENMODES
# ============================================================================
#
# Bessel zeros are roots of Jₙ(x)=0.
# They are not parameters — they are mathematical facts about the wave
# equation on a disk. We do not choose them; we read them.
#
# N_STRANDS = 4 bases × 2 spirals = 8
#   The two-spiral structure (DNA + Kuramoto) follows from the basin having
#   one exogenous and one endogenous drive. 4 bases per spiral is the
#   information capacity of 2-bit genome encoding. 4×2=8 is not chosen.
#
# N_RADIAL = count of Bessel zeros fitting inside R at the φ-derived scale
#   This is not a count we set — it is whatever the basin geometry permits.
#   At GRID=64, R≈24: BZ[n][m]/BZ[n][last]·R·scale < R for m=0..3. So N_RADIAL=4.
#
# N_DSLOTS = N_STRANDS · N_RADIAL = 32
#   A consequence, not a target.
#

glyph bessel_modes
    id     = BESSEL
    class  = BASIS
    state  = EXECUTED
    parent = { BASIN, BASE4_MAP }

    BZ          = EMERGENT   # roots of Jₙ(x)=0 — mathematical facts
    N_STRANDS   = EMERGENT   # BASE4_MAP.n_bases · 2
    N_RADIAL    = EMERGENT   # count fitting inside R at φ-derived scale
    N_DSLOTS    = EMERGENT   # N_STRANDS · N_RADIAL
    radial_scale = EMERGENT  # 1 − dslot_shell.half_width/R
    bz_r        = EMERGENT   # BZ[n][m]/BZ[n][last] · R · radial_scale
    threshold   = EMERGENT   # √φ — the binary gate
end


# ============================================================================
# LAYER 8: WAVE FIELD — (θ,A) PHASE REPRESENTATION
# ============================================================================
#
# The field is not a simulation. It is the analog representation itself.
# θ ∈ S¹ — phase lives on the circle. Wrap events are topological, not numerical.
# A ∈ ℝ⁺ — amplitude is non-negative by definition of energy.
#
# The field equations are the complex wave equation in polar coordinates:
#   cos(Δθ): real part of complex Laplacian → amplitude coupling
#   sin(Δθ): imaginary part → Kuramoto phase synchronisation
# These are not two separate equations bolted together.
# They are one equation — the complex wave equation — read in (A,θ) coordinates.
#
# γ (damping) comes from LOCK_TRACKER — itself emergent from φ.
# ω₀ = 0: the natural frequency is zero because the basin is driven by
# geometry, not by an external clock. Zero IS the emergent frequency
# of a basin with no external time reference.
#

glyph wave_field
    id     = WAVE_FIELD
    class  = STATE
    state  = EXECUTED
    parent = { BASIN, L_OPERATOR, LAMBDA_PHI }

    theta      = EMERGENT   # θᵢ ∈ [0,2π) — oscillator phase on S¹
    amp        = EMERGENT   # Aᵢ ∈ [0,A_MAX] — amplitude envelope on ℝ⁺
    drive      = EMERGENT   # U(t)[i] — boundary forcing

    equations  = EMERGENT   # complex wave equation in polar coordinates:
                             # dA = −γAᵢ + CF2·Σcos(Δθ) + drive
                             # dθ = ω₀  + CF2·Σsin(Δθ)/Aᵢ
                             # Euler step DT=φ⁻¹

    memory     = EMERGENT   # NCELLS3·(3·8+4·4) bytes — 3 double + 4 float fields
end


# ============================================================================
# LAYER 9: FOUR TEMPORAL PROJECTIONS
# ============================================================================
#
# The EMA decay coefficient IS φ⁻¹.
# The EMA growth coefficient IS 1−φ⁻¹ = φ⁻².
# These sum to 1: φ⁻¹ + φ⁻² = (φ+1)/φ² = φ²/φ² = 1 ✓ (from φ²=φ+1)
# The partition of unity is the axiom.
#
# Four channels because four DNA bases — the same count, the same
# information capacity, the same reason. Each contributes π/2 to Θ
# because 2π/4 = π/2: four equal parts of the full circle.
# The tiling of [0,2π) by 4 channels is the base-4 alphabet in angular form.
#
# T_SPIN is the primary LOCK indicator because |dθ/dt|→0 at the fixed
# point of the rewrite operator Ωₙ₊₁=T(Ωₙ). The spin rate is how far
# the field is from its fixed point, measured in angular velocity.
#

glyph temporal_projections
    id     = T_PROJ
    class  = PROJECTION
    state  = EXECUTED
    parent = { WAVE_FIELD, PHI }

    decay          = EMERGENT   # φ⁻¹ — IS the inverse of the axiom
    growth         = EMERGENT   # 1−φ⁻¹ = φ⁻² — complement, from φ²=φ+1
    channel_count  = EMERGENT   # 4 — same as DNA base count
    channel_width  = EMERGENT   # 2π/4 = π/2 — tiling of S¹ by 4

    T_FWD          = EMERGENT   # φ⁻¹·T_FWD + φ⁻²·Aᵢ — amplitude history [A]
    T_BWD          = EMERGENT   # φ⁻¹·T_BWD + φ⁻²·|dA/dt| — rate [C]
    T_PACE         = EMERGENT   # T_FWD/(T_BWD+A_EPS) — local time-rate [G]
    T_SPIN         = EMERGENT   # φ⁻¹·T_SPIN + φ⁻²·|dθ/dt| — spin rate [T]

    Theta          = EMERGENT   # θ_xy+θ_z+θᵢ·(2π)⁻¹·(π/2)+Σ[channels]·(π/2)
end


# ============================================================================
# LAYER 10: TWO SPIRALS
# ============================================================================
#
# Spiral 1 is exogenous: genome_fp → hardware DNA → boundary forcing.
# Spiral 2 is endogenous: field synchronisation → Kuramoto base identity → boundary forcing.
# Two spirals because the basin has two surfaces of influence:
# what enters from outside (genome) and what the field generates inside (synchronisation).
# The coupling scale in both cases is 1/N_BASES — each base contributes equally.
#

glyph spiral_dna
    id     = SPIRAL_DNA
    class  = DRIVE
    state  = EXECUTED
    parent = { WAVE_FIELD, L_OPERATOR, LAMBDA_PHI, ONE_EFF, BASE4_MAP, BASIN }

    n_range   = EMERGENT   # {0,1,2,3} — first spiral occupies the first 4 angular orders
    strands   = EMERGENT   # {A,B,C,D} — D-slots 1..16
    source    = EXOGENOUS

    N_BASES       = EMERGENT   # 32/2 = 16 — genome_fp bit-width / bits-per-base
    bits_per_base = EMERGENT   # 2 — log₂(4) — information capacity of 4-base alphabet

    drive
        theta_k  = EMERGENT   # k·(2π/N_BASES) + Ω(tick)·2π — φ-log phase of tick
        L_amp_k  = EMERGENT   # 𝓛ₙ(Ω(tick)) — full UFE amplitude, not Dₙ approximation
        coupling = EMERGENT   # cos(n_k·(Θ−θ_k))·L_amp_k/N_BASES
    end
end

glyph spiral_kuramoto
    id     = SPIRAL_KURA
    class  = DRIVE
    state  = EXECUTED
    parent = { WAVE_FIELD, L_OPERATOR, LAMBDA_PHI, ONE_EFF, BASE4_MAP, BASIN }

    n_range   = EMERGENT   # {4,5,6,7} — second spiral at next 4 angular orders
    strands   = EMERGENT   # {E,F,G,H} — D-slots 17..32
    source    = ENDOGENOUS

    base_identity
        # The phase quadrant of strand j's deviation from the mean field
        # IS the base identity of overtone strand j+4.
        # It cannot be anything else — the quadrant and the base are the same partition.
        Δφ_j      = EMERGENT   # φ_j − kur_Psi
        quadrant  = EMERGENT   # (Δφ_j mod 2π)/(π/2) → {0,1,2,3} → {A,C,G,T}
    end

    order_parameter
        phi_j     = EMERGENT   # 2π·j/N_FUND + Ω(tick)·2π — natural phase on S¹
        Z         = EMERGENT   # (1/N_FUND)·Σ Aⱼ·e^(i·φ_j) — mean-field
        kur_R     = EMERGENT   # |Z| — synchronisation strength
        kur_Psi   = EMERGENT   # arg(Z) — mean-field phase
        N_FUND    = EMERGENT   # N_STRANDS/2 = 4 — fundamentals drive overtones
    end

    drive
        # φ-taper: convergent series Σφ⁻ʲ = 1/(1−φ⁻¹) = φ — sum IS the axiom
        phi_taper = EMERGENT   # φ⁻ʲ for j=0..N_FUND−1
        K         = EMERGENT   # from LOCK_TRACKER — φ-derived
        coupling  = EMERGENT   # K·kur_R·𝓛ₙ(Ω)·φ⁻ʲ/N_BASES
    end
end


# ============================================================================
# LAYER 11: ADAPTIVE LOCK TRACKER
# ============================================================================
#
# The lock states are the four regions of the φ-power spectrum of T_SPIN:
#   PLUCK:    T_SPIN ∈ [φ⁰, ∞)     field freely rotating — drive hard
#   SUSTAIN:  T_SPIN ∈ [φ⁻⁵, φ⁰)  partial synchronisation — moderate drive
#   FINETUNE: T_SPIN ∈ [φ⁻¹⁰,φ⁻⁵) near fixed point — gentle
#   LOCK:     T_SPIN ∈ [0, φ⁻¹⁰)  at fixed point — wu-wei
#
# The thresholds φ⁰, φ⁻⁵, φ⁻¹⁰ are the powers that tile the PLUCK→LOCK
# range into four equal φ-decades (each spanning 5 φ-powers = one φ-half-octave).
#
# K[j] = N_FUND · φ^(1−j) for j=0..3
#   K descends the φ-harmonic series as the field locks.
#   K_PLUCK/K_LOCK = φ^(1−0)/φ^(1−3) = φ³ — the ratio is the cube of the axiom.
#
# γ[j] = CF2 · φ^(−j) for j=0..3
#   Damping ascends as the field locks — more damping at LOCK preserves the eigenmode.
#   γ_LOCK/γ_PLUCK = φ^(−3)/φ⁰ = φ⁻³ — the ratio is the cube-inverse of the axiom.
#
# K[j]·γ[j] = N_FUND·φ^(1−j) · CF2·φ^(−j) = N_FUND·CF2·φ^(1−2j)
# K/γ = N_FUND/CF2 = 4·3·φ⁴ = 12·φ⁴ — constant across ALL states.
# The K/γ balance is scale-invariant: the axiom preserves the ratio.
#
# LOCK ↔ T_SPIN < φ⁻¹⁰ ↔ CV < 1/φ^10 ≈ 0.008
# ll_analog uses CV < 0.05 — a coarser threshold. Both express the same
# convergence condition: the field has reached the fixed point of T(Ω).
# θ → 2θ mod 2π  ↔  sₖ₊₁ = sₖ²−2  (phase doubling = Lucas-Lehmer squaring)
#

glyph lock_tracker
    id     = LOCK_TRACKER
    class  = ADAPTIVE
    state  = EXECUTED
    parent = { WAVE_FIELD, SPIRAL_KURA, PHI }

    thresholds = EMERGENT   # {φ⁰, φ⁻⁵, φ⁻¹⁰} — φ-power boundaries of spin spectrum

    states
        PLUCK
            threshold = EMERGENT   # T_SPIN ≥ φ⁰ = 1
            K         = EMERGENT   # N_FUND·φ¹ = 4φ
            gamma     = EMERGENT   # CF2·φ⁰
            meaning   = EMERGENT   # field far from fixed point
        end
        SUSTAIN
            threshold = EMERGENT   # T_SPIN ∈ [φ⁻⁵, φ⁰)
            K         = EMERGENT   # N_FUND·φ⁰ = 4
            gamma     = EMERGENT   # CF2·φ⁻¹
            meaning   = EMERGENT   # field converging
        end
        FINETUNE
            threshold = EMERGENT   # T_SPIN ∈ [φ⁻¹⁰, φ⁻⁵)
            K         = EMERGENT   # N_FUND·φ⁻¹ = 4φ⁻¹
            gamma     = EMERGENT   # CF2·φ⁻²
            meaning   = EMERGENT   # field near fixed point
        end
        LOCK
            threshold = EMERGENT   # T_SPIN < φ⁻¹⁰
            K         = EMERGENT   # N_FUND·φ⁻² = 4φ⁻²
            gamma     = EMERGENT   # CF2·φ⁻³
            meaning   = EMERGENT   # Ωₙ₊₁=T(Ωₙ) stable — wu-wei
        end
    end

    K_gamma_ratio = EMERGENT   # N_FUND/CF2 = 12φ⁴ — constant across all states
    ll_identity   = EMERGENT   # θ→2θ mod 2π ↔ sₖ₊₁=sₖ²−2
end


# ============================================================================
# LAYER 12: D-SLOT READOUT
# ============================================================================
#
# The readout samples the basin's eigenmode amplitudes at the Bessel shell loci.
# The angular weight |cos(n·Θ)| is exact — zero at nodal lines is correct physics.
# The binary threshold √φ is the unique value where φ self-intersects: √φ·√φ = φ.
#
# Extended slots 33..4096 are a φ-weighted blend of adjacent D-slot pairs.
# The weights are φ⁻¹ and φ⁻² — the same partition-of-unity as the EMA channels.
# The modulation φ^(−7·(k+1)) is the same φ-decay series as 1_eff.
# All three are the same statement: the axiom applied to consecutive indices.
#
# The normalisation scale 2/max(dslots) maps to [0,2] so that the threshold
# √φ ≈ 1.272 sits at the natural midpoint between 0 and 2·φ⁻¹ = 2/φ ≈ 1.236.
# The interval [0,2] is [0, 2·φ⁰] — one full φ-unit span.
#

glyph dslot_readout
    id     = DSLOT
    class  = READOUT
    state  = EXECUTED
    parent = { WAVE_FIELD, BESSEL, T_PROJ, L_OPERATOR }

    readout
        per_cell  = EMERGENT   # Aᵢ·|cos(n·Θ)| — amplitude at nodal weight
        per_slot  = EMERGENT   # mean over Bessel annulus
        Theta     = EMERGENT   # full Θ from T_PROJ — phase-sensitive sampling
    end

    normalise
        scale     = EMERGENT   # 2/max(dslots) — maps to [0, 2·φ⁰]
        threshold = EMERGENT   # √φ — φ self-intersection point
        d_bits    = EMERGENT   # bit i ↔ dslot[i] > √φ
    end

    extended
        # Slots 33..4096: φ-weighted blend, φ-decay modulation
        # Same structure as T_PROJ EMA (φ⁻¹, φ⁻²) and 1_eff (φ^(−(n+β)))
        formula   = EMERGENT   # φ⁻¹·d[i%32] + φ⁻²·d[(i+1)%32] + φ^(−7·(i%8+1))·φ⁻¹
        range     = EMERGENT   # {N_DSLOTS+1 .. GRID²} = {33..4096}
    end

    precision   = EMERGENT   # Kuramoto R=1.000 on shell; phase error 1.4×10⁻¹⁵ rad/step
    capacity    = EMERGENT   # 2^32 d_bits states; 8192:1 compression; ~27 bits entropy
end


# ============================================================================
# LAYER 13: RUNTIME
# ============================================================================
#
# The settle and loop drive amplitudes are readings of CF2 and its φ-powers.
# Drive at CF2 amplitude: one unit of wave energy per eigenmode per step.
# Modulation at CF2·φ⁻¹: the drive breathes at the φ-ratio of the Courant factor.
# Period round(φ^13) = 521: the 13th φ-power, the natural long cycle of the lattice.
#
# Seed amplitude φ⁻⁴ ≈ 0.146: the smallest φ-power that produces a visible
# basin perturbation above A_EPS. Four φ-inverses from unity.
# Seed phase Ω(genome_fp & 0xFFFF)·2π: the φ-log resonance of the genome
# maps to the initial phase — the basin opens at the resonance of the hardware.
#
# sleep_ms = 50: the filesystem write interval. This is the one quantity in
# the file that is not from φ — it is a system parameter that determines how
# often D-slot values are written to disk. It does not affect the physics.
# The substrate runs at the speed of CF2; the filesystem runs at 50ms.
#

glyph runtime
    id     = RUNTIME
    class  = RUNTIME
    state  = INIT
    parent = { BASIN, WAVE_FIELD, SPIRAL_DNA, SPIRAL_KURA,
               LOCK_TRACKER, T_PROJ, DSLOT }

    args
        genome_fp = EMERGENT   # hex — hardware DNA fingerprint
        tick      = EMERGENT   # hex — current tick count
        --slots   = EMERGENT   # path — D-slot output directory
        --settle  = EMERGENT   # N — default: 2·GRID·T_depth steps
        --update  = EMERGENT   # N — default: GRID·T_depth/4 steps
        --omega   = EMERGENT   # ω₀ — default 0 (geometry-driven)
    end

    seed
        amp_centre   = EMERGENT   # φ⁻⁴ — four φ-inverses from unity
        theta_centre = EMERGENT   # Ω(genome_fp & 0xFFFF)·2π
    end

    settle
        lock_start  = EMERGENT   # PLUCK — field begins far from fixed point
        drive_peak  = EMERGENT   # CF2·φ⁻¹·(1−φ⁻¹) = CF2·φ⁻¹·φ⁻²
        drive_base  = EMERGENT   # drive_peak·φ⁻¹
        drive_sweep = EMERGENT   # drive_peak·sin(2π·s/(settle/4)) + drive_base
    end

    loop
        drive_mean = EMERGENT   # CF2 — Courant amplitude
        drive_mod  = EMERGENT   # CF2·φ⁻¹ — one φ-step of drive
        drive_amp  = EMERGENT   # CF2·(1 + φ⁻¹·sin(2π·step/round(φ^13)))
        period     = EMERGENT   # round(φ^13) = 521
        sleep_ms   = 50         # filesystem write interval — not physics
    end

    state_output   = EMERGENT   # all keys — what the substrate reports about itself

    rule init
        match     = state INIT
        transform = {
            PHI.recognise,         # read the axiom
            FIB.recognise,         # read the Fibonacci identity
            PRIMES.recognise,      # read the prime identity
            BASIN.recognise,       # read the geometric identity
            BESSEL.recognise,      # read the Bessel identity
            ALLOC_FIELDS,
            PRECOMPUTE_SHELLS,
            SEED_CENTRE,
            BUILD_DRIVE_MAP
        }
        advance = CONFIGURED
    end

    rule settle
        match     = state CONFIGURED
        transform = SETTLE_LOOP
        advance   = DISCOVERED
    end

    rule run
        match     = state DISCOVERED
        transform = MAIN_LOOP
        advance   = EXECUTED
    end

    rule stop
        match     = signal { SIGTERM, SIGINT }
        transform = FREE_FIELDS
        advance   = TERMINATED
    end
end


# ============================================================================
# LAYER 14: SELF-LOAD
# ============================================================================
#
# phi_fold(content_hash(phi_pool.hdgl), genome_fp) = 𝓛(this file)
# This file IS the fixed point of the operator it describes.
# Loading it = the operator recognising itself.
# Ωₙ₊₁ = T(Ωₙ)
#

glyph phi_pool_self
    id     = PHI_POOL_SELF
    class  = BOOTSTRAP
    state  = INIT
    parent = { PHI, L_OPERATOR, LAMBDA_PHI, ONE_EFF, LOCK_TRACKER,
               BASIN, BESSEL, WAVE_FIELD, T_PROJ,
               SPIRAL_DNA, SPIRAL_KURA, DSLOT, RUNTIME }

    rule self_load
        match     = state INIT
        transform = {
            CONTENT_HASH,
            PHI_FOLD → L_OPERATOR.formula,
            PHI_TAU_STRAND,
            FABRIC_STORE,
            OMEGA_REGISTER
        }
        advance = EXECUTED
    end
end

